home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / MPW Extras ƒ / MPW / Scripts / NewOpen < prev    next >
Encoding:
Text File  |  1991-08-29  |  6.8 KB  |  164 lines  |  [TEXT/MPS ]

  1. # NewOpen - replacement "Open" script supporting file backup and remember
  2.  
  3. Set ScriptName "{0}"                                                                            # save the script's name
  4. Set NFile "{#}"                                                                                    # get number of command line arguments
  5. If ({NFile} == 0)
  6.     # no Command Line arguments - Open will use NewGetFile dialog box
  7.     Set CmdStr "`Begin; NewGetFile -t TEXT; Set OpenStatus {Status}; End`" ≥≥ Dev:Null
  8.     If ({OpenStatus} == 0)
  9.         # a file was selected - try to open it
  10.         Open {CmdStr} ∑∑ Dev:Null                                                                # invoke NewGetFile to select a filename
  11.         Set OpenStatus {Status}
  12.         If ({OpenStatus} == 0)
  13.             # the Open was successful - perform the backup and remember chores
  14.             ReadOnlyStatus "{Active}" ∑∑ Dev:Null                                                # test if this is a read-only file
  15.             If ({Status} == 0)
  16.                 Set LeafName "`ParseFileName -l "{Active}"`"                                    # get the file's leafname
  17.                 Duplicate -y "{Active}" "{Backup}" ∑∑ "{Worksheet}" || Beep                        # create the Backup file
  18.     
  19.                 # Delete all the old "Remember" backup files
  20.                 For i in `Begin; Files -f "{Backup}{LeafName}".[0-9]+; End ≥ Dev:Null`
  21.                     Delete "{i}"
  22.                 End  # For i
  23.             End  # If {Status}
  24.         Else
  25.             Alert "{ScriptName}:∂nUnable to open the file {CmdStr}."
  26.         End  # If {OpenStatus}
  27.     Else
  28.         If ({OpenStatus} != 4)
  29.             # an error occured that was not a user cancellation
  30.             Alert "{ScriptName}:∂nUnable to continue due to NewGetFile error #{NewStatus}."
  31.         End  # If {OpenStatus}
  32.     End  # If {OpenStatus}
  33. Else
  34.     Loop
  35.         Break If ({NFile} <= 0)                                                                    # exit if all arguments have been processed
  36.         If (("{1}" == "-n") || ("{1}" == "-r") || ("{1}" == "-t"))
  37.             # a command line option has been encountered
  38.             If (("{2}" == "-n") || ("{2}" == "-r") || ("{2}" == "-t"))
  39.                 # a second command Line option has been encountered
  40.                 If (("{3}" == "-n") || ("{3}" == "-r") || ("{3}" == "-t"))
  41.                     # a third command line option has been encountered
  42.                     If ("{4}" != "")
  43.                         Set ShiftSize 4
  44.                         Open "{1}" "{2}" "{3}" ∑∑ Dev:Null
  45.                     Else
  46.                         Set ShiftSize 3
  47.                         Open "{1}" "{2}" "{3}" "{4}" ∑∑ Dev:Null
  48.                     End  # If {4}
  49.                     Set OpenStatus {Status}
  50.                     If ({OpenStatus} == 0)
  51.                         # the Open was successful - perform the backup and remember chores
  52.                         ReadOnlyStatus "{Active}" ∑∑ Dev:Null                                    # test if this is a read-only file
  53.                         If ({Status} == 0)
  54.                             If (("{1}" != "-n") && ("{2}" != "-n") && ("{2}" != "-n"))
  55.                                 DeRez -only "'MPSR' (1006)" "{Worksheet}" > DeRez.tmp            # get the standard print options from the Worksheet
  56.                                 Rez -a -o "{Active}" DeRez.tmp                                    # transfer to the target file
  57.                                 Delete DeRez.tmp                                                # delete the temporary file
  58.                             End  # If {1}
  59.                             Set LeafName "`ParseFileName -l "{Active}"`"                        # get the file's leafname
  60.                             Duplicate -y "{Active}" "{Backup}" ∑∑ "{Worksheet}" || Beep            # create the backup file
  61.  
  62.                             # Delete all the old "Remember" backup files
  63.                             For i in `Begin; Files -f "{Backup}{LeafName}".[0-9]+; End ≥ Dev:Null`
  64.                                 Delete "{i}"
  65.                             End  # For i
  66.                         End  # If {Status}
  67.                     Else
  68.                         # an error occured that was not a user cancellation
  69.                         Alert "{ScriptName}:∂nUnable to open file {4} with options {1} {2} {3}."
  70.                     End  # If {OpenStatus}
  71.                 Shift {ShiftSize}
  72.                 Evaluate NFile -= {ShiftSize}                                                    # update the argument counter
  73.                 Else
  74.                     If ("{3}" != "")
  75.                         Set ShiftSize 3
  76.                         Open "{1}" "{2}" "{3}" ∑∑ Dev:Null
  77.                     Else
  78.                         Set ShiftSize 2
  79.                         Open "{1}" "{2}" ∑∑ Dev:Null
  80.                     End  # If {3}
  81.                     Set OpenStatus {Status}
  82.                     If ({OpenStatus} == 0)
  83.                         # the Open was successful - perform the backup and remember chores
  84.                         ReadOnlyStatus "{Active}" ∑∑ Dev:Null                                    # test if this is a read-only file
  85.                         If ({Status} == 0)
  86.                             If (("{1}" != "-n") && ("{2}" != "-n"))
  87.                                 DeRez -only "'MPSR' (1006)" "{Worksheet}" > DeRez.tmp            # get the standard print options from the Worksheet
  88.                                 Rez -a -o "{Active}" DeRez.tmp                                    # transfer to the target file
  89.                                 Delete DeRez.tmp                                                # delete the temporary file
  90.                             End  # If {1}
  91.                             Set LeafName "`ParseFileName -l "{Active}"`"                        # get the file's leafname
  92.                             Duplicate -y "{Active}" "{Backup}" ∑∑ "{Worksheet}" || Beep            # create the backup file
  93.  
  94.                             # Delete all the old "Remember" backup files
  95.                             For i in `Begin; Files -f "{Backup}{LeafName}".[0-9]+; End ≥ Dev:Null`
  96.                                 Delete "{i}"
  97.                             End  # For i
  98.                         End  # If {Status}
  99.                     Else
  100.                         # an error occured that was not a user cancellation
  101.                         Alert "{ScriptName}:∂nUnable to open file {3} with options {1} {2}."
  102.                     End  # If {OpenStatus}
  103.                 Shift {ShiftSize}
  104.                 Evaluate NFile -= {ShiftSize}                                                    # update the argument counter
  105.                 End  # If {3}
  106.             Else
  107.                 If ("{2}" != "")
  108.                     Set ShiftSize 2
  109.                     Open "{1}" "{2}" ∑∑ Dev:Null
  110.                 Else
  111.                     Set ShiftSize 1
  112.                     Open "{1}"  ∑∑ Dev:Null
  113.                 End  # If {2}
  114.                 Set OpenStatus {Status}
  115.                 If ({OpenStatus} == 0)
  116.                     # the Open was successful - perform the backup and remember chores
  117.                     ReadOnlyStatus "{Active}" ∑∑ Dev:Null                                        # test if this is a read-only file
  118.                     If ({Status} == 0)
  119.                         If ("{1}" != "-n")
  120.                             DeRez -only "'MPSR' (1006)" "{Worksheet}" > DeRez.tmp                # get the standard print options from the Worksheet
  121.                             Rez -a -o "{Active}" DeRez.tmp                                        # transfer to the target file
  122.                             Delete DeRez.tmp                                                    # delete the temporary file
  123.                         End  # If {1}
  124.                         Set LeafName "`ParseFileName -l "{Active}"`"                            # get the file's leafname
  125.                         Duplicate -y "{Active}" "{Backup}" ∑∑ "{Worksheet}" || Beep                # create the backup file
  126.  
  127.                         # Delete all the old "Remember" backup files
  128.                         For i in `Begin; Files -f "{Backup}{LeafName}".[0-9]+; End ≥ Dev:Null`
  129.                             Delete "{i}"
  130.                         End  # For i
  131.                     End  # If {Status}
  132.                 Else
  133.                     # an error occured that was not a user cancellation
  134.                     Alert "{ScriptName}:∂nUnable to Open file {2} with option {1}."
  135.                 End  # If {OpenStatus}
  136.             Shift {ShiftSize}
  137.             Evaluate NFile -= {ShiftSize}                                                        # update the argument counter
  138.             End  # If {2}
  139.         Else
  140.             Open "{1}" ∑∑ Dev:Null
  141.             Set OpenStatus {Status}
  142.             If ({OpenStatus} == 0)
  143.                 # the Open was successful - perform the backup and remember chores
  144.                 ReadOnlyStatus "{Active}" ∑∑ Dev:Null                                            # test if this is a read-only file
  145.                 If ({Status} == 0)
  146.                     Set LeafName "`ParseFileName -l "{Active}"`"                                # get the file's leafname
  147.                     Duplicate -y "{Active}" "{Backup}" ∑∑ "{Worksheet}" || Beep                    # create the backup file
  148.  
  149.                     # Delete all the old "Remember" backup files
  150.                     For i in `Begin; Files -f "{Backup}{LeafName}".[0-9]+; End ≥ Dev:Null`
  151.                         Delete "{i}"
  152.                     End  # For i
  153.                 End  # If {Status}
  154.             Else
  155.                 # an error occured that was not a user cancellation
  156.                 Alert "{ScriptName}:∂nUnable to open file {1}."
  157.             End  # If {OpenStatus}
  158.         Shift
  159.         Evaluate NFile -= 1                                                                        # update the argument counter
  160.         End  # If {1}
  161.     End  # Loop
  162. End  # If {NFile}
  163.  
  164. # end of NewOpen